package com.java.module.fire.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.fire.domain.Friends;
import com.java.module.fire.service.IFriendsService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 用户好友Controller
 * 
 * @author Administrator
 * @date 2025-02-10
 */
@RestController("AdminFriendsController")
@RequestMapping("/fire/friends")
public class FriendsController {
    @Autowired
    private IFriendsService friendsService;

    /**
     * 查询用户好友列表
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:list')")
    @GetMapping("/list")
    public TableDataInfo list(Friends friends) {
        WebKit.startPage();
        List<Friends> list = friendsService.selectFriendsList(friends);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出用户好友列表
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:export')")
    @Log(title = "用户好友", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Friends friends) {
        List<Friends> list = friendsService.selectFriendsList(friends);
        ExcelUtil<Friends> util = new ExcelUtil<Friends>(Friends.class);
        return util.exportExcel(list, "friends");
    }

    /**
     * 获取用户好友详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:query')")
    @GetMapping(value = "/{friendsId}")
    public AjaxResult getInfo(@PathVariable("friendsId") Long friendsId) {
        return AjaxResult.success(friendsService.selectFriendsById(friendsId));
    }

    /**
     * 新增用户好友
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:add')")
    @Log(title = "用户好友", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Friends friends) {
        return WebKit.toAjax(friendsService.insertFriends(friends));
    }

    /**
     * 修改用户好友
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:edit')")
    @Log(title = "用户好友", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Friends friends) {
        return WebKit.toAjax(friendsService.updateFriends(friends));
    }

    /**
     * 删除用户好友
     */
    @PreAuthorize("@ss.hasPermi('fire:friends:remove')")
    @Log(title = "用户好友", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{friendsIds}")
    public AjaxResult remove(@PathVariable Long[] friendsIds) {
        return WebKit.toAjax(friendsService.deleteFriendsByIds(friendsIds));
    }
}
